<template>
  <div class="layui-row">
      <!-- 头部导航块 -->
      <top-lump>
        <div class="layui-btn-group">
            <span class="layui-breadcrumb kgo-top-lump-breadcrumb" lay-separator="#">
                <a># 新增项目模块</a>
            </span>
        </div>
      </top-lump>
      <info-lump>
        <base-card title="新增项目模块">
            <table class="layui-table">
                <colgroup>
                    <col>
                    <col width="40%">
                    <col>
                    <col width="40%">
                </colgroup>
                <tbody>
                    <tr>
                        <td>模块名称</td>
                        <td class="kgo-input-td"><input  v-model="thisModule.name" name="name" type="text" class="kgo-input-text"/></td>
                        <td>父模块</td>
                        <td class="kgo-input-td"><alone-select :selected="thisModule.parentModuleId" url="/module/code" ref="getParentModule"  name="parentModule"></alone-select></td>
                    </tr>
                    <tr>
                        <td>模块状态</td>
                        <td class="kgo-input-td"><alone-select :selected="thisModule.status" catalogueCode="standard_type" ref="getStatus"  name="status"></alone-select></td>
                        <td>模块类别</td>
                        <td class="kgo-input-td"><alone-select :selected="thisModule.type" catalogueCode="standard_type" ref="getType"  name="type"></alone-select></td>
                    </tr>
                    <tr>
                        <td>版本号</td>
                        <td class="kgo-input-td"><input v-model="thisModule.version" name="version" type="text" class="kgo-input-text"/></td>
                        <td>模块路径</td>
                        <td class="kgo-input-td"><input v-model="thisModule.url" name="url" type="text" class="kgo-input-text"/></td>
                    </tr>
                    <tr>
                        <td>关键字</td>
                        <td class="kgo-input-td" colspan="3"><input v-model="thisModule.keyword" name="keyword" type="text" class="kgo-input-text"/></td>
                    </tr>
                    <tr>
                        <td>项目描述</td>
                        <td class="kgo-input-td" colspan="3"> <lay-edit :content="thisModule.remark" ref="getEidt"></lay-edit> </td>
                    </tr>
                    <tr>
                        <td>项目排序</td>
                        <td class="kgo-input-td"><input v-model="thisModule.index"  name="index" type="text" class="kgo-input-text"/></td>
                        <td>项目描述</td>
                        <td class="kgo-button-td">
                            <div class="layui-btn-group">
                               
                                <button class="layui-btn" v-if="isEdit" v-on:click="editModule">更新</button>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>

        </base-card>
      </info-lump>


  </div>
</template>

<script>

export default {
    components: {

    },
    data () {
        return {
            thisModule:{},
            isEdit:false
        }
    }, 
    created(){
        console.log("new ddd");
        var moduleId = this.$route.params.id;
        if(KgoUtil.objIsNotNull(moduleId)){
            this.initModule(moduleId);
            this.isEdit = true;
        }else{
           this.isEdit = false;
           this.thisModule = {};
        }
    },
   mounted(){
       layui.form.render('select');
   },
   methods:{
      emptyEdit:function(){
           //this.$refs.getEidt.emptyEdit();
      },
      initModule:function(id){
           var url = this.$store.state.RootURL + "/module/id";
           var that = this;
           $.ajax({
                url: url,
                type:"get",
                async: true,
                dataType:'json',
                data: {"id":id},
                success: function(data){
                    console.log("当前模块信息 ：" + JSON.stringify(data));
                    that.thisModule=data.data;
                }
            });
      },
      editModule:function(){
           
            var that = this;
            if( this.thisModule.name==null|| this.thisModule.name==""){
                layer.msg("模块名称不能为空！请检查");
                return;
            }
            if( this.thisModule.version==null|| this.thisModule.version==""){
                layer.msg("模块版本号不能为空！请检查");
                return;
            }
             this.thisModule.remark = this.$refs.getEidt.getHtml();
             this.thisModule.status = this.$refs.getStatus.getSelected();
             this.thisModule.parentModuleId = this.$refs.getParentModule.getSelected();
             this.thisModule.type = this.$refs.getType.getSelected();
             this.thisModule.projectId = this.$store.state.projectId;
             console.log("模块状态 ：" +JSON.stringify(this.thisModule));

            var url = this.$store.state.RootURL + "/module";
            $.post(url,that.thisModule,function(result){
                layer.msg(result.msg);
                if(result.success){
                  that.emptyEdit();
                }
            },"json");

        },

   }
}
</script>

<style lang="scss">
.kgo-input-text{
    height: 35px;
    width: 100%;
    border-radius: 5px;
    border: 1px solid #e6e6e6;
}

</style>
